package com.kxmall.admin.controller.storage;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.admin.controller.storage.service.IKxStorageManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.storage.domain.vo.KxStorageVo;
import com.kxmall.storage.domain.bo.KxStorageBo;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 仓库管理
 */
@Api(tags = "仓库管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/storage/manage")
public class KxStorageManageController extends BaseController {

    private final IKxStorageManageService iKxStorageManageService;

    /**
     * 查询全部仓库列表
     */
    @SaIgnore
    @ApiOperation(value = "/storage/manage/listAll - 查询全部仓库列表", httpMethod = "GET")
    @GetMapping("/listAll")
    public R<List<KxStorageVo>> listAll(KxStorageBo bo) {
        return R.ok(iKxStorageManageService.queryList(bo));
    }
    /**
     * 导出全部仓库列表
     */
    @SaCheckPermission("storage:manage:export")
    @Log(title = "导出全部仓库列表", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "/storage/manage/export - 导出全部仓库列表", httpMethod = "POST")
    @PostMapping("/export")
    public void export(KxStorageBo bo, HttpServletResponse response) {
        List<KxStorageVo> list = iKxStorageManageService.queryList(bo);
        ExcelUtil.exportExcel(list, "仓库管理", KxStorageVo.class, response);
    }
    /**
     * 分页查询仓库列表
     */
    @SaCheckPermission("storage:manage:pageList")
    @ApiOperation(value = "/storage/manage/pageList - 分页查询仓库列表", httpMethod = "GET")
    @GetMapping("/pageList")
    public TableDataInfo<KxStorageVo> pageList(KxStorageBo bo, PageQuery pageQuery) {
        return iKxStorageManageService.queryPageList(bo, pageQuery);
    }
    /**
     * 获取仓库管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("storage:manage:query")
    @ApiOperation(value = "/storage/manage/query/{id} - 获取仓库管理详细信息", httpMethod = "GET")
    @GetMapping("/query/{id}")
    public R<KxStorageVo> query(@NotNull(message = "主键不能为空")
                                  @PathVariable Long id) {
        return R.ok(iKxStorageManageService.queryById(id));
    }
    /**
     * 新增仓库管理
     */
    @SaCheckPermission("storage:manage:add")
    @Log(title = "新增仓库管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "/storage/manage/add - 新增仓库管理", httpMethod = "POST")
    @PostMapping("/add")
    @RepeatSubmit()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KxStorageBo bo) {
        return toAjax(iKxStorageManageService.insertByBo(bo));
    }
    /**
     * 修改仓库管理
     */
    @SaCheckPermission("storage:manage:edit")
    @Log(title = "修改仓库管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "/storage/manage/edit - 修改仓库管理", httpMethod = "PUT")
    @PutMapping("/edit")
    @RepeatSubmit()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KxStorageBo bo) {
        return toAjax(iKxStorageManageService.updateByBo(bo));
    }

    /**
     * 删除仓库管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("storage:manage:remove")
    @Log(title = "删除仓库管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "/storage/manage/remove/{ids} - 删除仓库管理", httpMethod = "DELETE")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iKxStorageManageService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
    /**
     * 仓库状态批量更新为正常
     */
    @ApiOperation(value = "/storage/manage/updateStateToNormal - 仓库状态批量更新为正常", httpMethod = "POST")
    @PostMapping("/updateStateToNormal")
    public R<Boolean> updateStateToNormal(@RequestBody KxStorageBo bo){
        return R.ok(iKxStorageManageService.updateStateToNormal(bo));
    }
    /**
     * 仓库状态批量更新为禁用
     */
    @ApiOperation(value = "/storage/manage/updateStateToAbort - 仓库状态批量更新为禁用", httpMethod = "POST")
    @PostMapping("/updateStateToAbort")
    public R<Boolean> updateStateToAbort(@RequestBody KxStorageBo bo){
        return R.ok(iKxStorageManageService.updateStateToAbort(bo));
    }
    /**
     * 仓库营业状态批量更新为营业中
     */
//    @ApiOperation(value = "/storage/manage/updateBusinessStateToOpen - 仓库营业状态批量更新为营业中", httpMethod = "POST")
//    @PostMapping("/updateBusinessStateToOpen")
//    public R<Boolean> updateBusinessStateToOpen(@RequestBody KxStorageBo bo){
//        return R.ok(iKxStorageManageService.updateBusinessStateToOpen(bo));
//    }
    /**
     * 仓库营业状态批量更新为休息中
     */
//    @ApiOperation(value = "/storage/manage/updateBusinessStateToRest - 仓库营业状态批量更新为休息中", httpMethod = "POST")
//    @PostMapping("/updateBusinessStateToRest")
//    public R<Boolean> updateBusinessStateToRest(@RequestBody KxStorageBo bo){
//        return R.ok(iKxStorageManageService.updateBusinessStateToRest(bo));
//    }
    /**
     * 仓库营业状态批量更新为休息中
     */
//    @ApiOperation(value = "/storage/manage/options - 仓库营业状态批量更新为休息中", httpMethod = "POST")
//    @PostMapping("/options")
//    public R<List<KxStorageVo>> options(){
//        return R.ok(iKxStorageManageService.options());
//    }
    /**
     * 获取指定仓库的推送订阅二维码
     */
//    @ApiOperation(value = "/storage/manage/getStorageQrcodeImage - 获取指定仓库的推送订阅二维码", httpMethod = "POST")
//    @PostMapping("/getStorageQrcodeImage")
//    public R<String> getStorageQrcodeImage(){
//        return R.ok(iKxStorageManageService.getStorageQrcodeImage());
//    }
    /**
     * 打印测试
     */
//    @ApiOperation(value = "/storage/manage/printTest - 打印测试", httpMethod = "POST")
//    @PostMapping("/printTest")
//    public R<Boolean> printTest(@RequestBody KxStorageBo bo){
//        return R.ok(iKxStorageManageService.printTest(bo));
//    }

}
